
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">


</head>
<body>
<form class="layui-form" method="post" action="/student/updateSave">
    <%-- 隐藏域--%>
        <input type="hidden" name="sId" value="${student.sId}">
        <div class="layui-form-item">
            <label class="layui-form-label">学号</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="studentNum" value="${student.studentNum}" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="studentName"value="${student.studentName}" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="男" title="男" checked>
                <input type="radio" name="gender" value="女" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="age" value="${student.age}" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">出生日期</label>
            <div class="layui-input-block">
                <input type="text" id="birthDate" name="dateOfBirth" value="${student.dateOfBirth}" placeholder="请选择出生日期" autocomplete="off" class="layui-input">
            </div>
        </div>


        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">班级</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="classId" value="${student.classId}" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="phone" value="${student.phone}" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

</form>
<script src="/static/layui/layui.js"></script>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    layui.use(['laydate'], function(){
        var laydate = layui.laydate;

        // 渲染日期选择器
        laydate.render({
            elem: '#birthDate', // 绑定元素
            format: 'yyyy-MM-dd', // 指定日期格式
            value: '${student.dateOfBirth}' // 初始值
        });
    });

    $(document).ready(function() {
        // 获取出生日期输入框
        var birthDateInput = $('#birthDate');

        // 将英文日期格式转换为数字格式
        function formatDateString(dateStr) {
            var date = new Date(dateStr);
            if (isNaN(date)) {
                return ''; // 无效日期
            }
            var year = date.getFullYear();
            var month = ('0' + (date.getMonth() + 1)).slice(-2);
            var day = ('0' + date.getDate()).slice(-2);
            return year + '-' + month + '-' + day;
        }

        // 初始化时格式化日期
        var birthDateValue = birthDateInput.val();
        if (birthDateValue) {
            var formattedDate = formatDateString(birthDateValue);
            birthDateInput.val(formattedDate);
        }
    });
</script>

</body>
</html>
